package com.example.testcomposeproject.pages.testRefresh.solve

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.ViewModel
import com.example.testcomposeproject.MyLogger
import com.example.testcomposeproject.PreViewData
import com.example.testcomposeproject.ui.theme.AppTheme

/**
 * @author: hemin
 * @date: 2024/8/30
 * @Desc:
 */
@Preview(showBackground = true, device = PreViewData.PreviewPhoneSize)
@Composable
fun PreViewBSolveUI(modifier: Modifier = Modifier) {
    AppTheme {
        BSolveUI(modifier = modifier, clickBack = {}, clickNext = {

        },clickCount = 1,onIncrement = {})

    }
}


@Composable
fun BSolveScreen(modifier: Modifier = Modifier, viewModel: BViewModel = hiltViewModel(), clickBack:()->Unit, clickNext:()->Unit) {
    BSolveUI(modifier,clickCount = viewModel.clickCount, onIncrement = viewModel::increaseCount,clickNext = clickNext,clickBack = clickBack)
}


class BViewModel : ViewModel() {
    var clickCount by mutableStateOf(0)
        private set

    fun increaseCount() {
        clickCount++
    }
}
/**
 * 真正的UI元素
 */
@Composable
fun BSolveUI(modifier: Modifier = Modifier,  clickCount: Int, onIncrement: () -> Unit, clickNext:()->Unit,clickBack:()->Unit, ) {
  /*  var count by remember {
        mutableIntStateOf(bCount)
    }*/
    MyLogger.hLog().e("BSolveUI")
    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        //MyLogger.hLog().e("TestComposeCountUI count = $count")   去掉注释后 看你执行不  不会执行
        Text(text ="BSolveUI ")

        Text(text = "$clickCount")
        Button(onClick = {onIncrement()
        }) {
            Text(text = "点击")
        }

        Column {
            Text(text = "看你执行不")
            MyLogger.hLog().e("看你执行不")

        }


        Row (modifier = Modifier.fillMaxWidth(), horizontalArrangement = androidx.compose.foundation.layout.Arrangement.SpaceBetween){
            Button(onClick = {
                MyLogger.hLog().e("上一页 点击")
                clickBack()
            }) {
                Text(text = "上一页")

                MyLogger.hLog().e("上一页 点击Scope重组")
            }

            Button(onClick = {
                MyLogger.hLog().e("下一页 点击")
                clickNext()
            }) {
                Text(text = "下一页")

                MyLogger.hLog().e("下一页 点击Scope重组")
            }
        }

        MyLogger.hLog().e("==========================")

    }

}